import React, {PureComponent} from 'react';

import moment from 'moment';

import { Input, Button } from 'antd'; 

export default class CommentInput extends PureComponent {
    constructor(props) {
        super();

        this.state = {
            content: ""
        }
    }

    render() {  
        return (
            <div>
                <Input.TextArea rows={4} 
                value={this.state.content}
                onChange={e => this.handleChange(e)}/>
                <Button type="primary" onClick={e => this.addComment()}>添加评论</Button>
            </div>
        )
    }

    handleChange(event) {
        this.setState({
            content: event.target.value
        })
    }

    addComment() {
        const commentInfo = {
            id: moment().valueOf(),
            avatar: 'https://portrait.gitee.com/uploads/avatars/user/3041/9124466_leonreboot_1621167775.png!avatar60',
            nickname: 'leon',
            datetime: moment(),
            content: this.state.content
        }

        this.props.submitComment(commentInfo);

        this.setState({
            content: ""
        })
    }

   
}